package com.woniuxy.moneyapp.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.moneyapp.infra.CashRecordDao;
import com.woniuxy.moneyapp.infra.dto.CashDtoToShow;
import com.woniuxy.moneyapp.infra.dto.MyCashRecord;
import com.woniuxy.moneyapp.infra.model.CashRecord;
import com.woniuxy.moneyapp.service.CashRecordService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author seven
 * @since 2022-08-01
 */
@Service
public class CashRecordServiceImpl extends ServiceImpl<CashRecordDao, CashRecord> implements CashRecordService {

    @Override
    public Page<CashDtoToShow> getCashRecord(MyCashRecord copyObject) {
        Integer pageNum = copyObject.getPageNum();
        Integer pageSize = copyObject.getPageSize();
        Page<CashDtoToShow> page = baseMapper.cashRecord(new Page(pageNum == null ?
                1 : pageNum,
                pageSize == null ?
                        5 : pageSize),copyObject);
        List<CashDtoToShow> records = page.getRecords();
        Collections.reverse(records);
        page.setRecords(records);
        return page;
    }
}
